# !/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName  :create_task.py
# @Time      :2025/7/9 18:33
# @Author    :aiyimu

import asyncio

async def fetch_data(url, delay):
    print(f"开始获取 {url}")
    await asyncio.sleep(delay)
    print(f"完成获取 {url}")
    return f"{url} 数据"

async def main():
    # 创建任务但不立即等待
    task1 = asyncio.create_task(fetch_data("https://site1.com", 1))
    task2 = asyncio.create_task(fetch_data("https://site2.com", 2))

    # 执行其他操作
    print("其他同步操作执行中...")

    # 等待任务完成
    result1 = await task1
    result2 = await task2

    print(f"结果1: {result1}\n结果2: {result2}")

asyncio.run(main())